home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
WINDCOM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-04
|
12KB
|
483 lines
#include "pt.h"
#include "ctype.h"
#include "string.h"
#include "io.h"
void pascal
/* XTAG:doNewWindow */
doNewWindow(fn, fullScreen)
int fn;
{
extern unsigned char msgBuffer[];
extern unsigned char textBuffer[];
extern int scrRows, scrCols;
extern int menuLine;
register unsigned char *fileName;
int n, row1, row2, col1, col2;
if( fullScreen ) {
row1 = row2 = (menuLine > 0 ? 1 : 0);
col1 = col2 = 0;
} else if( getBox(0, 0, &row1, &col1, &row2, &col2, 0) == 2 )
goto cancelWindow;
if( row1 == row2 && col1 == col2 ) {
row2 = scrRows-1;
if( menuLine < 0 )
--row2;
col2 = scrCols-1;
}
/* do not allow very small windows */
if( row2 < row1+2 || col2 < col1+10 ) {
msg("Size too small, no window created", 1);
return;
}
if( fn == FNEWWINDOW )
fileName = getFileName("File to load into the new window: ");
else /* fn == FNEWSEL -- file name is the selection */
fileName = getSelection(&textBuffer[0]);
if( fileName == NULL ) {
cancelWindow:
msg("Window create cancelled", 1);
return;
}
if( fileName[0] == '\0' ) {
strcpy(fileName, "UnNamed.a");
(void)makeName(fileName);
}
fileName = noWhiteSpace(fileName);
strcpy(textBuffer, fileName);
if( access(textBuffer, 0) == -1 ) {
sprintf(msgBuffer, "y to create «%s»: ", textBuffer);
fileName = getInput(msgBuffer, "y", 1);
if( fileName == NULL || tolower(*fileName) != 'y' )
goto cancelWindow;
n = creatls(textBuffer, 0);
if( n < 0 ) {
sprintf(msgBuffer, "Cannot create «%s»: ",
textBuffer);
msg(msgBuffer, 3);
goto cancelWindow;
} else
closels(n);
}
createWindow(textBuffer, row1, col1, row2, col2, CRTOP, 0);
}
unsigned char * pascal
/* XTAG:noWhiteSpace */
noWhiteSpace(fileName)
register unsigned char *fileName;
{
register int n;
if( fileName != NULL || fileName[0] == '\0' ) {
/* eliminate white space around fileName */
/* first white space in the beginning */
while( isspace(*fileName) )
++fileName;
/* now white space at the end */
n = strlen(fileName) - 1;
while( isspace(fileName[n]) )
--n;
fileName[n+1] = '\0';
}
return fileName;
}
void pascal
/* XTAG:bottomFile */
bottomFile(w)
register struct window *w;
{
extern int debug;
long cp;
int fid, j;
register int i;
if( w == NULL )
return;
/* remember where we came from */
w->rowLastline = w->numTopline;
cp = w->posBotline;
fid = w->fileId; /* we'll use this a lot */
/* find the last line of the file */
i = 0;
while( 1 ) {
j = 1;
cp = nextLine(fid, cp, &j);
/* if j==0, we could not go down a line */
/* so we are at the end */
if( j == 0 )
break;
++i;
}
++i; /* one more line so EOF mark shows */
/* now move the window down and redraw it */
j = i; /* since i is a register variable, we must use j here */
w->posTopline = nextLine(fid, w->posTopline, &j);
w->posBotline = cp;
w->numTopline += j;
w->numBotline += j;
w->indent = 0;
redrawWindow(w);
}
void pascal
/* XTAG:loadWindow */
loadWindow(w, fn)
register struct window *w;
int fn;
{
extern struct window *selWindow;
extern long selBegin, selEnd;
extern unsigned char msgBuffer[];
extern unsigned char textBuffer[];
extern struct openFile *files;
int n;
unsigned char *fileName, saveName[64];
if( fn == FLOADFILE )
fileName = getFileName("File to load in window: ");
else /* fn == FLOADSEL -- get file name from the selection */
fileName = getSelection(&textBuffer[0]);
if( fileName == NULL )
goto cancelFileLoad;
if( fileName[0] == '\0' ) {
strcpy(fileName, "UnNamed.a");
makeName(fileName);
}
fileName = noWhiteSpace(fileName);
strcpy(saveName, fileName);
n = 0; /* we did NOT create 'saveName' */
if( access(saveName, 0) == -1 ) {
sprintf(msgBuffer, "y to create «%s»: ", saveName);
fileName = getInput(msgBuffer, "y", 1);
if( fileName == NULL || tolower(*fileName) != 'y' )
goto cancelFileLoad;
n = creatls(saveName, 0);
if( n < 0 ) {
sprintf(msgBuffer, "Cannot create «%s»: ", saveName);
msg(msgBuffer, 3);
goto cancelFileLoad;
} else
closels(n);
n = 1; /* we did create 'saveName' */
}
if( closeFile(w->fileId, 1) == -1 ) {
if( n ) /* delete 'saveName' if we created it */
delete(saveName);
cancelFileLoad:
msg("File load cancelled", 1);
return;
}
w->fileId = getFileId(saveName);
w->nameOffset = getBaseName(files[w->fileId].origName);
w->posTopline = 0;
w->numTopline = 1;
w->posCurLast = 0;
w->lastPosTop = 0;
w->rowCurLast = 0;
w->indent = 0;
if( w == selWindow ) {
selBegin = selEnd = 0;
if( readChar(w->fileId, 0L) == '\r' ) {
if( readChar(w->fileId, 1L) == '\n' )
selEnd = 1;
}
}
/* get the state of unixMode */
w->state = getUnixState(w->fileId);
redrawWindow(w);
}
void pascal
/* XTAG:hideWindow */
hideWindow(w)
register struct window *w;
{
extern struct window *windowList;
extern struct window *activeWindow;
extern struct window *hiddenList;
extern struct window *selWindow;
extern long selBegin, selEnd;
extern int scrRows, scrCols;
if( w == NULL )
return;
/* unlink the window from the list of active windows */
if( w->prevWindow != NULL )
w->prevWindow->nextWindow = w->nextWindow;
else /* must be first on the list -- the top window */
windowList = w->nextWindow;
if( w->nextWindow != NULL )
w->nextWindow->prevWindow = w->prevWindow;
/* stack w onto the hidden list */
w->nextWindow = hiddenList;
hiddenList = w;
/* is the selection in this window? */
if( w == selWindow ) {
/* move the selection to the top window */
selWindow = windowList;
if( selWindow != NULL ) {
selBegin = 0;
selEnd = 0;
if( readChar(selWindow->fileId, 0L) == '\r' ) {
if( readChar(selWindow->fileId, 1L) == '\n' )
selEnd = 1;
}
}
}
/* is this the active window? */
if( w == activeWindow )
activeWindow = windowList;
/* redraw the screen */
redrawBox(0, 0, scrRows-1, scrCols-1);
updateScreen(0, scrRows-1);
}
void pascal
/* XTAG:doContextMenu */
doContextMenu()
{
extern struct window *windowList;
extern struct window *hiddenList;
extern int menuRow, menuCol;
extern struct menuBlock far *menus[];
extern struct openFile *files;
extern int pathNames;
int i, n, k;
struct window *newW;
register struct window *w2;
/* put in the title of the menu */
menus[0]->cmdName[0] = (unsigned char far *)"TOPLIST";
menus[0]->cmdNumber[0] = 0;
/* go through the list of visible windows */
n = 1;
i = 1;
w2 = windowList;
while( w2 != NULL && n < MAXMENUITEMS ) {
k = (pathNames ? 0 : w2->nameOffset);
menus[0]->cmdName[n] = (unsigned char far *)
&(files[w2->fileId].origName[k]);
menus[0]->cmdNumber[n] = i;
w2 = w2->nextWindow;
++n;
++i;
}
if( hiddenList != NULL && n < MAXMENUITEMS ) {
/* put in a divider line */
menus[0]->cmdName[n] = (unsigned char far *)"════════════";
menus[0]->cmdNumber[n] = 0;
++n;
}
/* now go through the list of hidden windows */
w2 = hiddenList;
/* use "command" numbers in the 300's to indicate hidden */
/* windows. This avoids conflicts with the real command */
/* number from 1 to ~150. For ~100 to ~150 they are option */
/* setting commands and so they ignore the string you send in. */
i = 301; /* number the entries */
while( w2 != NULL && n < MAXMENUITEMS ) {
k = (pathNames ? 0 : w2->nameOffset);
menus[0]->cmdName[n] =
(unsigned char far *)&(files[w2->fileId].origName[k]);
menus[0]->cmdNumber[n] = i;
w2 = w2->nextWindow;
++n;
++i;
}
/* now display the menu */
menus[0]->nItems = n;
i = menu(menus[0], menuRow, menuCol);
/* find out which window to top (or unhide and top) */
if( i == 0 )
return;
if( i > 300 ) { /* unhide and top a hidden window */
i -= 301;
if( i == 0 ) {
newW = hiddenList;
hiddenList = hiddenList->nextWindow;
} else {
w2 = hiddenList;
while( --i > 0 )
w2 = w2->nextWindow;
newW = w2->nextWindow;
/* unlink